/**
 * Created with IntelliJ IDEA.
 * Description:
 * https://gitee.com/li--jiaqiang/java-test.git
 * git pull
 * git pull origin master
 * git pull origin master --allow-unrelated-histories
 * User: 86187
 * Date: 2022-04-22
 * Time: 22:56
 */

//Scanner scan = new Scanner(System.in);

import java.util.Arrays;
import java.util.Scanner;

public class TestNode2 {

    /**
     * 将数组中的偶数放在前面，奇数放在后面
     * @param array
     */
    public static void swap(int[] array) {
        int left = 0;
        int right = array.length - 1;

        while(left < right) {

            while(left < right && array[left] % 2 == 0) {
                            //数组从前开始找奇数
                left++;
            }
            while(left < right && array[right] % 2 != 0) {
                //数组从后往前找偶数
                right--;
            }

            if(left < right) {
                int tmp = array[left];
                array[left] = array[right];
                array[right] = tmp;
            }

        }
    }

    public static void main(String[] args) {
        int[] array = {3,5,7,1,6,4,25,76,45,521};

        swap(array);
        System.out.println(Arrays.toString(array));
        System.out.println("");
    }
}
